<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

    protected function _initDoctrine()
    {
        $this->getApplication()->getAutoloader()
                ->pushAutoloader(array('Doctrine_Core', 'autoload'));
        spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
        spl_autoload_register(array('Doctrine_Core', 'extensionsAutoload'));

        $doctrineOp = $this->getOption('doctrine');
        Doctrine_Core::setModelsDirectory($doctrineOp['models_path']);
        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setCharset($doctrineOp['charset']);
        $manager->setCollate($doctrineOp['collade']);
        $manager->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, 'ix_%s');

        Doctrine_Core::loadModels($doctrineOp['models_path']);

        $conn = Doctrine_Manager::connection($doctrineOp['dsn'], 'doctrine');
        /* Uncomment to log queries */
        //$conn->setListener(new CMS_Doctrine_Logger());
        $conn->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
        $conn->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_TYPE, $doctrineOp['table_type']);

        return $conn;
    }

    protected function _initSession()
    {
        $config = array(
            'name' => 'Session',
            'dataColumn' => 'session_data',
            'lifetimeColumn' => 'lifetime',
            'modifiedColumn' => 'session_modified',
            'idColumn' => 'id',
        );

        Zend_Session::setSaveHandler(new CMS_Session_SaveHandler_Doctrine($config));
    }

    protected function _initPaths()
    {
        $paths = $this->getOption('paths');
        Zend_Registry::set('paths', $paths);
    }

}
